import { create } from "zustand";
import { ITodoList } from "../pages/todoList/model/todoList";

type CounterState = {
  count: number;
  increment: () => void;
  decrement: () => void;
};

type TodoState = {
  data: Array<ITodoList>;
  handleChange: (event: any, item: ITodoList) => void;
  handleDel: (index: number) => void;
  handleAdd: () => void;
};

export const useCounterStore = create<CounterState>()((set) => ({
  count: 0,
  increment: () => set((state: any) => ({ count: state.count + 1 })),
  decrement: () => set((state: any) => ({ count: state.count - 1 })),
}));

export const useTodoStore = create<TodoState>((set) => ({
  data: [],
  handleChange: (event: any, item: ITodoList) => {},
  handleDel: (index: number) => {
    set((state: any) => {
      let newData = [...state.data];
      newData.splice(index, 1);
      return { data: newData };
    });
  },
  handleAdd: () => {},
}));

export const useStore = create(() => {
  return {
    ...useCounterStore(),
    ...useTodoStore(),
  };
});
